<include file="Public/head" title="个人资料"/>
<include file="Public/back_head"/>
<div class="main">
    <div class="person_heard">
        <div class="person_img_1 clear">
            <a href="javascript:void(0)">
                头像<i class="iconfont icon-zuoyoujiantou2"></i>
                <div class="img_warp" id="upload_image">
                    <img src="{$user.headimgurl}" id="touxiang" alt="" />
                </div>
                <div class="b_border"></div>
            </a>
        </div>
        <div class="person_name1">
            <a href="javascript:void(0)">昵称 <span><input type="text" value="{$user.nickname}" id="nicheng"/><i class="iconfont icon-zuoyoujiantou2"></i></span></a>
        </div>
        <div class="person_real1">
            <a href="{:U('auth_info')}">
                实名认证 <i class="iconfont icon-zuoyoujiantou2"></i>
            	<if condition="$user.is_validate eq 1 ">    
                <span>已认证</span>
                <else/>
                <span style="color:red">未认证</span>
            	</if>
            </a>
        </div>
        <div class="person_url1"><a href="{:U('address')}">收货地址管理 <i class="iconfont icon-zuoyoujiantou2"></i></a></div>
    </div>
</div>

<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
    wx.config({
        debug : false,
        appId : "{$signPackage['appId']}", // 必填，公众号的唯一标识
        timestamp:"{$signPackage['timestamp']}", // 必填生成签名的时间戳
        nonceStr : "{$signPackage['nonceStr']}", // 必填生成签名的随机串
        signature : "{$signPackage['signature']}",// 必填签名，见附录1
        jsApiList : [ 'getLocation', 'checkJsApi', 'chooseImage',
                'uploadImage', 'downloadImage', 'previewImage' ]
    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });
        wx.ready(function() {
                    document.querySelector('#upload_image').onclick = function() {
                        var images = {
                            localId : [],
                            serverId : []
                        };
                        if ($("input[name='localId[]']").length >= 1) {
                            layer.open({
                                content : '仅限1张照片',
                                skin : 'msg',
                                time : 2
                            });
                            return false;
                        }

        wx.chooseImage({
            count : 6 - $("input[name='localId[]']").length, // 默认9
            sizeType : [ 'compressed' ],
            sourceType : [ 'album', 'camera' ],
            success : function(res) {
                var localIds = res.localIds;
                var i = 0, length = localIds.length;
                function upload() {
                    wx.uploadImage({
                    localId : localIds[i].toString(),
                    success : function(res) {
                        var str = '';
                        var localData = '';
                        //判断是否是苹果
                        var ua = window.navigator.userAgent.toLowerCase();
                        var s = ua.match(/IPhone/i);
                        str = '';
                        if(s){
                            wx.getLocalImgData({
                                localId: localIds[i].toString(), // 图片的localID
                                success: function (ress) {    
                               
                                  localData = ress.localData; 
                                  alert(localData);
                                $("#touxiang").attr("src",localData);

                                  save(res.serverId);
                                }
                              });
                        }else{
                             $("#touxiang").attr("src",localIds[i].toString());
                              save(res.serverId);
                           }
                        i++;
                        if (i < length) {
                            upload();
                        }
                    },
                    fail : function(res) {
                        layer.msg(JSON.stringify(res));
                    }
                });
                }
            upload();
            }
        });
    };
});

function save(server){
   $.post("{:U('save_image')}",{id:server}, function(data) {
            if(data.status == '1'){
                layer.msg(data.info),time(1000);
                setTimeout("location.href='"+data.url+"'",1500);
            }else{
                layer.msg(data.info);
            }
        });
}
$('#nicheng').change(function(){
    var name = $('#nicheng').val();
     $.post("{:U('save_name')}",{name:name}, function(data) {
            if(data.status == '1'){
                layer.msg(data.info),time(1000);
                setTimeout("location.href='"+data.url+"'",1500);
            }else{
                layer.msg(data.info);
            }
        });

});
    </script>
<include file="Public/foot"/>